/*** Eclipse Class Decompiler plugin, copyright (c) 2016 Chen Chao (cnfree2000@hotmail.com) ***/
package controller;

import entity.Vacabulary;
import entity.bean.Page;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import service.VocabularyService;

@Controller
public class VocabularyAction {

	@Resource
	private VocabularyService vocabularyService;

	@RequestMapping({ "/showvocal" })
	public String showvocal(Model model, Page page) {
		page = this.vocabularyService.pageVoca(page);
		model.addAttribute("page", page);
		return "jsonlist";
	}

	@RequestMapping(value = { "/addvaca" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST })
	public String addvoca(Model model, Vacabulary vaca) {
		try {
			this.vocabularyService.saveVoca(vaca);
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("result", "false");
			return "jsonlist";
		}
		model.addAttribute("result", "true");
		return "jsonlist";
	}

	@RequestMapping(value = { "/deletevoca" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST })
	public String deletevoca(Model model, long id) {
		try {
			this.vocabularyService.deletevoca(id);
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("result", "false");
			return "jsonlist";
		}
		model.addAttribute("result", "true");
		return "jsonlist";
	}
}